<?php
/**
 *author:栗超
 *address:2788547340@qq.com
 * 2016/9/4 14:02
 */
namespace Home\Controller;
use Common\Model\Address;
use Common\Model\From;
use Hdphp\Controller\Controller;
class FromController extends Controller{
    private $model;
    public function __init(){
        $this->model=new From();
    }
    public function index(){
        $addressModel = new Address();
        $addressData = $addressModel->where("user_uid",$_SESSION['uid'])->get();
//        p($addressData);
        View::with('addressData',$addressData);
        //显示数量和价格
//        $data=$_SESSION['cart']['goods'];
//        p($data);
        $num = 0;
        $total=0;
        foreach ($_SESSION['cart']['goods'] as $k => $v){
            $num = $v['num'] + $num;
            $total=$v['total'] + $total;
        }
        View::with('num',$num);
        View::with('total',$total);

        View::make();
    }
    public function add(){
        if(IS_POST){
            if($this->model->store()){
                View::success('添加成功',U('index'));
            }
            //提示相关错误信息
            View::error($this->model->getError());
        }
    }
}